package LeetCode.Medium;

// 从上到下打印出二叉树的每个节点，同一层的节点按照从左到右的顺序打印

import java.util.ArrayDeque;
import java.util.ArrayList;

public class Question007 {
    public void LevelOrder(TreeNode root){
        ArrayDeque<TreeNode> de = new ArrayDeque<>();
        de.add(root);
        while(!de.isEmpty()){
            TreeNode p = de.pop();
            System.out.println(p.val);
            if(p.left != null) de.add(p.left);
            if(p.right != null) de.add(p.right);
        }
    }
}
